package com.gxgeek.javabasic.ClassLoader;


import org.junit.*;
import org.junit.internal.runners.model.ReflectiveCallable;
import org.junit.internal.runners.statements.InvokeMethod;
import org.junit.runner.JUnitCore;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.FrameworkMethod;

import java.lang.annotation.Native;
import java.lang.reflect.Method;

/**
 * Created by gx on 2017/7/5.
 */
public class TestClassIdentity {

    @org.junit.Test
    public void testClassIdentity() {
        String classDataRootPath = "F:\\";
        FileSystemClassLoader fscl1 = new FileSystemClassLoader(classDataRootPath);
        FileSystemClassLoader fscl2 = new FileSystemClassLoader(classDataRootPath);
        String className = "Sample";
        try {
            Class<?> class1 = fscl1.loadClass(className);
            Object obj1 = class1.newInstance();
            Class<?> class2 = fscl2.loadClass(className);
            Object obj2 = class2.newInstance();
            Method setSampleMethod = class1.getMethod("setSample", Object.class);
            setSampleMethod.invoke(obj1, obj2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    java.lang.reflect.InvocationTargetException
//    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
//    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//    at java.lang.reflect.Method.invoke(Method.java:498)
//    at com.gx.ClassLoader.TestClassIdentity.testClassIdentity(TestClassIdentity.java:25)
//    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
//    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//    at java.lang.reflect.Method.invoke(Method.java:498)
//    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
//    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
//    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
//    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
//    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
//    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
//    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
//    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
//    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
//    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
//    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
//    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
//    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
//    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
//    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
//    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
//    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
//    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
//    Caused by: java.lang.ClassCastException: Sample cannot be cast to Sample
//    at Sample.setSample(Sample.java:9)
//	... 27 more

//
//    public static void main(String[] args) {
//
//    }
}
